package com.advert.provider.support;

import com.advert.dto.ModelSearchCriteria;
import com.advert.model.support.*;
import com.advert.provider.ProviderBase;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import java.util.List;

@Name("SupportProvider")
@Scope(ScopeType.EVENT)
@AutoCreate
public class SupportProvider extends ProviderBase {

    @SuppressWarnings("unchecked")
    public List<VehicleTypeEntity> getVehicleTypes() {
        return entityManager.createNamedQuery("VehicleTypeEntity.getAll").getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<VehicleCategoryEntity> getVehicleCategories() {
        return entityManager.createNamedQuery("VehicleCategoryEntity.getAll").getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<VehicleBrandEntity> getVehicleBrands() {
        return entityManager.createNamedQuery("VehicleBrandEntity.getAll").getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<VehicleModelEntity> searchVehicleModels(ModelSearchCriteria criteria) {
        return entityManager.createNamedQuery("VehicleModelEntity.searchModel").
                setParameter("typeCode", criteria.getTypeCode()).
                setParameter("categoryCode", criteria.getCategoryCode()).
                setParameter("brandId", criteria.getBrandId()).
                getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<CurrencyEntity> getCurrencies() {
        return entityManager.createNamedQuery("CurrencyEntity.getAll").
                getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<VehicleStateEntity> getVehicleStates() {
        return entityManager.createNamedQuery("VehicleStateEntity.getAll").getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<RegionEntity> getRegions() {
        return entityManager.createNamedQuery("RegionEntity.getAll").getResultList();
    }
}
